package com.hdy.web.controller;

import com.hdy.web.dao.ReplyMapper;
import com.hdy.web.pojo.Reply;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.List;

@Controller
public class ReplyController {
    final ReplyMapper replyMapper;

    public ReplyController(ReplyMapper replyMapper) {
        this.replyMapper = replyMapper;
    }
    @RequestMapping("/reply")
    public String addReply(@Param("mid") int mid, @Param("postId") String fromId, @Param("toId") String toId,
                           @Param("pContent") String pContent, @Param("content")String content, @Param("qid") int qid,
                           @Param("question") String question, @Param("date") Date date,Model model){
        Reply entity=new Reply();
        replyMapper.insertReply(mid,fromId,toId,content,pContent,entity);
        /*model.addAttribute("qid",qid);
        model.addAttribute("postId",fromId);
        model.addAttribute("question",question);
        model.addAttribute("date",date);*/
        return "forward:detailing";
    }

    @RequestMapping("/rr")
    public String showReply(Model model, HttpSession session){
        try {
            String toId = (String) session.getAttribute("userName");
            List<Reply> replies = replyMapper.getByToId(toId);
            model.addAttribute("replies",replies);
            return "reply2";
        } catch (Exception e) {
            return "reply2";
        }

    }
}
